package com.bianguo.android.pigeondemo.view.activity;

import android.Manifest;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.bianguo.android.pigeondemo.Presenter.MainPresenter;
import com.bianguo.android.pigeondemo.R;
import com.bianguo.android.pigeondemo.model.MainModel;
import com.bianguo.android.pigeondemo.utils.PermissionHelper;
import com.bianguo.android.pigeondemo.view.IMainView;

import java.util.Random;

import butterknife.OnClick;

public class MainActivity extends BaseActivity<IMainView, MainModel, MainPresenter> implements IMainView {

    @Override
    public int layoutId() {
        return R.layout.activity_main;
    }

    @Override
    public MainPresenter initPresenter() {
        return new MainPresenter(this);
    }

    @Override
    public void initView(@Nullable Bundle savedInstanceState) {
        if (mPresenter != null) {
            mPresenter.getMovieList();
        }
    }

    @OnClick({R.id.main_text})
    public void onClickBk(View view) {
        switch (view.getId()) {
            case R.id.main_text:
                TextView tv = (TextView) view;
                Random random = new Random();
                tv.setTextColor(Color.argb(255, random.nextInt(255), random.nextInt(255), random.nextInt(255)));
                if (mPresenter == null) {
                    PermissionHelper.getInstance(this).isPermission(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PermissionHelper.PERMISSION_WRITE);
                } else {
                    mPresenter.getMovieList();
                }
                break;
        }
    }

    @Override
    public void failedView(String msg, int tag, boolean isRefresh) {
        showToast(msg);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
